import type { PiniaPluginContext } from "pinia";

export const createPiniaPersist = () => {
  return (context: PiniaPluginContext) => {
    const { store } = context;

    // 监听store变化
    store.$onAction(({ after }) => {
      after(() => {
        const { $id, ...rest } = store;
        localStorage.setItem(`pinia-store-${$id}`, JSON.stringify(rest));
      });
    });
  };
};
